package view;

import control.PassengerController;
import model.Passenger;
import org.w3c.dom.Text;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class VIPpay implements ActionListener{
    public static JFrame jfra;
    public static JPanel jpan1, jpan2,jpanLabel, jpanInput,myPanel,jpanMid, jpanBlank, jpanButton;
    public static JLabel company, MyTripLabel, LogInLabel, ServiceLabel, VIPLabel, ModifyLabel, ContactLabel,label, payNotice, payNotice1;;
    public static Font fnt3;
    public static JButton save,back;
    public static ImageIcon background;
    public static String currentPlaneNum;
    public static PassengerController passengerController = new PassengerController();
    public static LogIn logIn = new LogIn();
    public static String bookNumber = logIn.bookNumber;


    JTextField text4 = new JTextField(16);


    public void createPage(){
        jfra = new JFrame();


//setting the background
        background = new ImageIcon("src/view/image/background.png"); //Create a background image
        label = new JLabel(background);  //Add a background image to the label
        label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());//Set the label to be as wide as the image
        myPanel = (JPanel) jfra.getContentPane();  //Set myPanel to the Content panel
        myPanel.setOpaque(false);  //Make my panel invisible
        myPanel.setLayout(new FlowLayout());  //Set my panel to a flow layout
        jfra.getLayeredPane().setLayout(null);//Leave the layout of the layered panel blank

//create bar
        jpan1 = new JPanel();
        company = new JLabel("          Check-In Kiosk                    ", JLabel.LEFT);
        Font fnt = new Font("Serief", Font.BOLD, 40);
        company.setFont(fnt);
        LogInLabel = new JLabel("LogIn          ", JLabel.RIGHT);
        LogInLabel.setBackground(Color.YELLOW);
        MyTripLabel = new JLabel("MyTrip          ", JLabel.RIGHT);
        ServiceLabel = new JLabel("Service         ", JLabel.RIGHT);
        VIPLabel = new JLabel("VIP         ", JLabel.RIGHT);
        ModifyLabel = new JLabel("Board         ", JLabel.RIGHT);
        ContactLabel = new JLabel("Contact           ", JLabel.RIGHT);
        company.setForeground(Color.blue);
        jpan1.add(company);
        jpan1.add(LogInLabel);
        jpan1.add(MyTripLabel);
        jpan1.add(ServiceLabel);
        jpan1.add(VIPLabel);
        jpan1.add(ModifyLabel);
        jpan1.add(ContactLabel);
        jpan1.setVisible(true);


//create VIPpay box
        jpan2 = new JPanel(new BorderLayout());
        jpan2.setPreferredSize(new Dimension(320,460));
        jpan2.setBackground(Color.WHITE);
        jpan2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
                "pay")));//Add the specific border of the panel
        jpanBlank = new JPanel();
        jpanBlank.setPreferredSize(new Dimension(300,100));
        jpan2.add(jpanBlank, BorderLayout.NORTH);
        jpanBlank.setBackground(Color.WHITE);
//set middle panel
        jpanMid=new JPanel();
        jpanMid.setLayout(new GridLayout(2,1));
        jpanMid.setPreferredSize(new Dimension(300,250));
        jpanMid.setBackground(Color.WHITE);
        jpan2.add(jpanMid, BorderLayout.CENTER);

//Input the ID number
        jpanLabel = new JPanel(new FlowLayout());
        jpanLabel.setBackground(Color.WHITE);
        payNotice=new JLabel("Please Input Booking Number",JLabel.CENTER);
        //payNotice.setPreferredSize(new Dimension(300,50));
        Font fnt3 = new Font("Serief", Font.ITALIC, 20);// Setting the size and style of the font.
        payNotice.setFont(fnt3);
        payNotice.setForeground(Color.BLACK);
        payNotice1=new JLabel("for Extra Option",JLabel.CENTER);
        payNotice1.setFont(fnt3);
        payNotice1.setForeground(Color.BLACK);
        jpanLabel.add(payNotice);
        jpanLabel.add(payNotice1);
        jpanMid.add(jpanLabel);
        jpanLabel.setVisible(true);

//Booking number input box
        jpanInput=new JPanel();
        jpanInput.setBackground(Color.WHITE);
        text4 = new JTextField(16);
        Font fnt5 = new Font("Serief", Font.ITALIC, 18);
        text4.setFont(fnt5);
        text4.setHorizontalAlignment(JTextField.CENTER);//Setting this text box to center horizontally
        String info1 = "";
        text4.setText(info1);
        //text4.addFocusListener(new MyFocusListener(info1, text4));//添加焦点事件反映
        jpanInput.add(text4);
        jpanInput.setVisible(true);
        jpanMid.add(jpanInput);
        jpanMid.setVisible(true);
        jpan2.add(jpanMid);

        jpanButton = new JPanel(new FlowLayout());
        jpanButton.setPreferredSize(new Dimension(300,100));
        save = new JButton("Save the ID");
        back = new JButton("Go Back");
        save.addActionListener(this);//Calling the listener
        back.addActionListener(this);//Calling the listener
        jpanButton.setBackground(Color.WHITE);
        save.setBackground(Color.WHITE);//Set the background color of the button
        back.setBackground(Color.WHITE);//Set the background color of the button
        jpanButton.add(back);
        jpanButton.add(save);
        jpan2.add(jpanButton, BorderLayout.SOUTH);

//Set myPanel
        myPanel.add(jpan1);
        myPanel.add(jpan2,BorderLayout.CENTER);
        jfra.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//Set interface properties
        jfra.setBounds(300, 300, background.getIconWidth(), background.getIconHeight());
        jfra.setVisible(true);
        jfra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * Invoked when an action occurs.
     *
     * @param e the event to be processed
     */

    @Override
    public void actionPerformed(ActionEvent e) {
        boolean check = (e.getSource() == save);
        boolean goback = (e.getSource() == back);
        String ID = text4.getText();
        if (check) {
            if(ID.equals(bookNumber)) {
                jfra.setVisible(false);
                pay a = new pay();
                a.createPage();
            }
            else{
                JOptionPane.showMessageDialog(null, "YOU INPUT THE WRONG BOOKING NUMBER!", "Warning",JOptionPane.ERROR_MESSAGE);
                text4.setText("");
            }
        }
        if(goback){
            jfra.setVisible(false);
            MealSeatVIP page = new MealSeatVIP();
        }
    }
}

